<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/list.css">
    <script src="../js/jquery-3.5.1.js"></script>
    <script src="../js/utils.js"></script>
</head>

<body>
    <header>
        <div class="_t"><img src="../img/T.png" alt=""></div>
        <ul>
            <li class="active">
                <a href="../index.html">在线商城</a>
            </li>
            <li>
                坚果 R2
            </li>
            <li>
                <a href="./TNT_go.html">Smartisan TNT go</a>
            </li>
            <li>
                坚果 TNT 工作站
            </li>
            <li>
                Smartisan OS
            </li>
            <li>
                欢喜云
            </li>
            <li>
                应用
            </li>
            <li>
                论坛
            </li>
            <li>
                开发者支持
            </li>
            <li>
                荣誉与奖项
            </li>
            <li>
                加入我们
            </li>
            <li tabs-item-apps">
                下载 APP
            </li>
        </ul>
        <div class="h_r">
            <div class="icon_1"></div>
            <div class="icon_2"></div>
        </div>
    </header>
    <div class="top">
        <div class="top_content">
            <ul>
                <li class="active">概览</li>
                <li>OS 2.0</li>
                <li>技术规格</li>
            </ul>
            <div class="top_content_right">
                <input type="text">
                <img src="../img/1625536877263.jpg" alt="" id="search">
                <button class="btn_R2">坚果 R2</button>
                <button class="btn_TNT">TNT</button>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="content_left"></div>
        <div class="content_right">
            <p class="name"></p>
            <p class="price"></p>
            <button>加入购物车</button>
        </div>
    </div>
    <footer>
        <div class="footer_content">
            <div class="footer_content_top">
                <ul class="footer_left">
                    <li>
                        <h5>订单服务</h5>
                        <p>购买指南</p>
                        <p>送货政策</p>
                    </li>
                    <li>
                        <h5>服务支持</h5>
                        <p>自助服务</p>
                        <p>维修门店</p>
                    </li>
                    <li>
                        <h5>媒体中心</h5>
                        <p>新闻动态</p>
                        <p>官方视频</p>
                        <p>图片资源</p>
                    </li>
                    <li>
                        <h5>关注我们</h5>
                        <p>新浪微博</p>
                        <p>官方微信</p>
                        <p>荣誉奖项</p>
                    </li>
                </ul>
                <div class="right">
                    <h3>400 - 603 - 5000</h3>
                    <h5>周一到周日 9:00 - 18:00</h5>
                    <h5>(仅收市话费)</h5>
                    <button class="help">在线帮助</button>
                </div>
            </div>
            <div class="footer_content_bottom">
                <ul class="footer_bottom_top">
                    <li>Copyright © 2020 smartisan.com 版权所有</li>
                    <li>锤子商城隐私政策</li>
                    <li>锤子商城用户协议</li>
                    <li>资质证照</li>
                </ul>
                <ul class="footer_bottom_bottom">
                    <li>京 ICP 备 19048576 号 - 1</li>
                    <li><img src="../img/icon5.png" alt="" id="police"><span>京公网安备 11010502039854号</span></li>
                    <li>京食药网食备 202010031</li>
                </ul>
            </div>
        </div>
    </footer>
    <div class="gotop">回到顶部</div>
    <script>
        function GetRequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            ajax({
                url: 'http://10.9.46.151:8080/listtest',
                method: 'GET',
                success(res) {
                    res = JSON.parse(res)
                    for (let i = 0; i < res.length; i++) {
                        if (theRequest.sku_id == res[i].sku_id) {
                            $('.content').attr({ sku_id: res[i].sku_id })
                            $('.content_left').css({ backgroundImage: "url(" + res[i].image + ")" })
                            $('.name').text(res[i].name)
                            $('.price').text('¥' + res[i].price)
                        }
                    }
                }
            })
            return theRequest;
        }
        GetRequest()
    </script>
    <script>
        $('button').on('click', function (e) {
            e.preventDefault()
            const id = $('.content').attr('sku_id')
            ajax({
                url : "http://10.9.46.151:8080/list",
                method : "GET",
                success(res){
                    res=JSON.parse(res)
                    // console.log(res);
                    var arr=[]
                    for(let i = 0;i < res.length;i++){
                        arr.push(res[i].sku_id)
                    }
                    if(arr.indexOf(id)== -1){
                        ajax({
                            url:'http://10.9.46.151:8080/listtest',
                            method : "GET",
                            success(res){
                                res=JSON.parse(res)
                                for(let i = 0;i < res.length;i++){
                                    if(res[i].sku_id==id){
                                        res[i].num=1
                                        res=JSON.stringify(res[i])
                                        console.log(res);
                                        ajax({
                                            url : 'http://10.9.46.151:8080/addgoods',
                                            method : 'POST',
                                            data : res,
                                            dataType : 'json',
                                            success(res){
                                                window.location.href = `./shopcar.html?sku_id=${id}`
                                            }
                                        })
                                        
                                        
                                    }
                                }
                                
                            }
                        })
                    }
                    // window.location.href = `./shopcar.html?sku_id=${id}`
                }
            })
        })
    </script>
</body>

</html>